package com.abbas.CayTcore.ui

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import com.abbas.CayTcore.R
import com.abbas.CayTcore.base.BaseActivity
import com.abbas.CayTcore.converter.GZConverter
import com.abbas.CayTcore.databinding.ActivityAddCoreTypeBinding
import com.abbas.CayTcore.entity.TCoreBase
import com.abbas.CayTcore.presenter.AddCoreTypePresenter
import com.abbas.CayTcore.view.ViewContract
import kotlinx.android.synthetic.main.activity_add_core_type.*
import kotlinx.android.synthetic.main.activity_add_core_type.view.*

class AddCoreTypeActivity :
    BaseActivity<ViewContract.AddCoreTypeView, AddCoreTypePresenter, ActivityAddCoreTypeBinding>(),
    ViewContract.AddCoreTypeView {

    override fun initPresenter(): AddCoreTypePresenter = AddCoreTypePresenter()

    override fun startAddCore() {
        refresh.isRefreshing = true
    }

    override fun addSuccess(row: Long) {
        refresh.isRefreshing = false
    }

    override fun addFailure(e: Throwable) {
        refresh.isRefreshing = false
    }

    override fun initData() {

    }

    override fun initEvent() {
        add.setOnClickListener {
            presenter.addCore(
                TCoreBase(
                    length_til.editText?.text?.toString()?.toInt() ?: 0,
                    width_til.editText?.text?.toString()?.toInt() ?: 0,
                    height_til.editText?.text?.toString()?.toInt() ?: 0,
                    gz.editText?.text?.toString()?.toFloat() ?: 0f
                ).apply {
                    dz = 0f
                }
            )
        }
    }

    override fun getViewBinding(): ActivityAddCoreTypeBinding =
        ActivityAddCoreTypeBinding.inflate(layoutInflater)


}